/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * StaticticInvoice.java
 *
 * Created on 25-08-2011, 06:52:21
 */
package tuitionmanagement.gui;

import Business.StaticticBuss;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import tuitionmanagement.DAO.StaticticsDao;
import tuitionmanagement.entity.StaticticEntity;

/**
 *
 * @author XUAN
 */
public class StaticticInvoice extends javax.swing.JPanel {

    Vector vRow = new Vector();
    StaticticEntity st = new StaticticEntity();
    StaticticBuss stbuss = new StaticticBuss();
    StaticticsDao stdao = new StaticticsDao();
    ArrayList<StaticticEntity> list;


    /** Creates new form StaticticInvoice */
    public StaticticInvoice() {
        initComponents();
    }

    private void loadTableStatictics() {
        vRow.clear();
        
        Date searchFrom = dcFrom.getDate();
        Date searchTo = dcTo.getDate();
        list = stbuss.getStaticticByDate(searchFrom, searchTo);

        for (int i = 0; i < list.size(); i++) {
            Vector v = new Vector();

            st = list.get(i);
            v.addElement(st.getInvoiceId());
            v.addElement(st.getStudentName());
            v.addElement(st.getTotalMoney());
            v.addElement(st.getPaidMoney());
            v.addElement(st.getDept());

            vRow.addElement(v);
        }

        Vector vCol = new Vector();
        vCol.addElement("InvoiceId");
        vCol.addElement("StudentName");
        vCol.addElement("MoneyTotal");
        vCol.addElement("PaidMoney");
        vCol.addElement("Dept");

        DefaultTableModel tblModel = new DefaultTableModel(vRow, vCol);
        tbInvoiceStatictics.setModel(tblModel);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        dcFrom = new com.toedter.calendar.JDateChooser();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        dcTo = new com.toedter.calendar.JDateChooser();
        btnStatictics = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        lbmeassage = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbInvoiceStatictics = new javax.swing.JTable();
        jPanel5 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        txtStatictics = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        btnReport = new javax.swing.JButton();

        setLayout(new java.awt.GridBagLayout());

        jPanel1.setLayout(new java.awt.GridBagLayout());

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 0, 255));
        jLabel1.setText("Invoice Statictics");
        jPanel1.add(jLabel1, new java.awt.GridBagConstraints());

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 11, 0);
        add(jPanel1, gridBagConstraints);

        jPanel2.setLayout(new java.awt.GridBagLayout());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.ipadx = 100;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
        jPanel2.add(dcFrom, gridBagConstraints);

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel3.setText("From:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 5);
        jPanel2.add(jLabel3, gridBagConstraints);

        jLabel4.setText("To:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(5, 15, 0, 5);
        jPanel2.add(jLabel4, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.ipadx = 100;
        gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 1);
        jPanel2.add(dcTo, gridBagConstraints);

        btnStatictics.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnStatictics.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tuitionmanagement/icon/document.png"))); // NOI18N
        btnStatictics.setText("Statictics");
        btnStatictics.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStaticticsActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.ipadx = 30;
        gridBagConstraints.insets = new java.awt.Insets(0, 21, 0, 8);
        jPanel2.add(btnStatictics, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 11, 0);
        add(jPanel2, gridBagConstraints);

        jPanel3.setLayout(new java.awt.GridBagLayout());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.ipady = 30;
        jPanel3.add(lbmeassage, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        add(jPanel3, gridBagConstraints);

        jPanel4.setLayout(new java.awt.GridBagLayout());

        tbInvoiceStatictics.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        tbInvoiceStatictics.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "InvoiceId", "TotalMoney", "PaidMoney", "Dept"
            }
        ));
        jScrollPane1.setViewportView(tbInvoiceStatictics);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.ipadx = 550;
        gridBagConstraints.ipady = 200;
        jPanel4.add(jScrollPane1, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 11, 0);
        add(jPanel4, gridBagConstraints);

        jPanel5.setLayout(new java.awt.GridBagLayout());

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel5.setText("Statictics:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 20);
        jPanel5.add(jLabel5, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.ipadx = 150;
        jPanel5.add(txtStatictics, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(12, 3, 11, 50);
        add(jPanel5, gridBagConstraints);

        jPanel6.setLayout(new java.awt.GridBagLayout());

        btnReport.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnReport.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tuitionmanagement/icon/export1.png"))); // NOI18N
        btnReport.setText("Report");
        jPanel6.add(btnReport, new java.awt.GridBagConstraints());

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 11, 44);
        add(jPanel6, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void btnStaticticsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStaticticsActionPerformed
        // TODO add your handling code here:
        txtStatictics.setText("");
        lbmeassage.setText("");

        int result = tbInvoiceStatictics.getRowCount();
        loadTableStatictics();

        if (result == 0 && result == 0) {
            lbmeassage.setText("No results match.");
        } else {
            lbmeassage.setText(result + " results match.");            
        }

    }//GEN-LAST:event_btnStaticticsActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnReport;
    private javax.swing.JButton btnStatictics;
    private com.toedter.calendar.JDateChooser dcFrom;
    private com.toedter.calendar.JDateChooser dcTo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lbmeassage;
    private javax.swing.JTable tbInvoiceStatictics;
    private javax.swing.JTextField txtStatictics;
    // End of variables declaration//GEN-END:variables
}
